package com.yuanxiao.common.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by luozongsheng on 20/12/2016.
 */
public class CommomRandom {

    public static String buildRandomStr(int randomLength){
        Random random = new Random();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
        String str = "";
        for(int i=0;i<4;i++){
            str += random.nextInt(10);
        }
        str += sdf.format(new Date());
        for(int i=0;i<randomLength;i++){
            str += random.nextInt(10);
        }
        return str;
    }

    public static String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
